<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>删除一次得到子数组最大和</title>
</head>
<body>
  <script>
    function fn(arr) {
      let n = arr.length;
      let dp0 = arr[0], dp1 = 0;
      let maxSum = dp0;
      for (let i = 1; i < n; i++) {
        dp1 = Math.max(dp0, dp1 + arr[i]);
        dp0 = Math.max(dp0, 0) + arr[i];
        maxSum = Math.max(maxSum, Math.max(dp0, dp1));
      }
      return maxSum;
    }
    console.log(fn([1, -2, 0, 3]))
  </script>
</body>
</html>